//
//  OtherUserCemterViewController.m
//  CYWFrame
//
//  Created by Macx on 2017/10/14.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "OtherUserCemterViewController.h"

@interface OtherUserCemterViewController ()

@end

@implementation OtherUserCemterViewController{
    UIImageView *_headPic;
    UILabel     *_userName;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    self.view.backgroundColor = kWhiteColor;
    self.navigationItem.title = @"用户中心";
    
    _headPic = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, SW(6), SW(6))];
    _headPic.centerX = self.view.centerX;
    [self.view addSubview:_headPic];
    _headPic.layer.cornerRadius = _headPic.width/2;
    _headPic.layer.masksToBounds = YES;
    _headPic.contentMode = UIViewContentModeScaleAspectFill;
    _headPic.clipsToBounds = YES;
    [_headPic sd_setImageWithURL:[NSURL URLWithString:self.pic] placeholderImage:IMAGE(@"placeHolder")];
    
    _userName = [[UILabel alloc] initWithFrame:CGRectMake(0, _headPic.y+_headPic.height+10, SCREEN_WIDTH, [LZCTools textSizeWithText:@"xx" font:kUHSystemFontWithSize(14)].height)];
    [self.view addSubview:_userName];
    _userName.font = kUHSystemFontWithSize(14);
    _userName.textAlignment = NSTextAlignmentCenter;
    _userName.text = self.name;
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"操作" style:UIBarButtonItemStylePlain target:self action:@selector(navRightClick:)];

}
- (void)navRightClick:(id)sender {
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"操作当前用户" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    NSString *title;
    
    if ([self.blacklist isEqualToString:@"0"]) {
        title = @"拉入黑名单";
    }
    else {
        title = @"解除黑名单";
    }
    
    [alert addAction:[UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        if ([self.blacklist isEqualToString:@"0"]) {
            
            UIAlertController *alert2 = [UIAlertController alertControllerWithTitle:@"拉入黑名单" message:@"ta不能邀请你、私信你" preferredStyle:UIAlertControllerStyleAlert];
            
            [alert2 addAction:[UIAlertAction actionWithTitle:@"点错了，手抖了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            }]];
            
            [alert2 addAction:[UIAlertAction actionWithTitle:@"确认添加" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                NSDictionary *param = @{@"to_user_id":self.to_user_id};
                
                [[NetworkTool sharedTool] requestWithName:@"拉入黑名单" URLString:APIUserBlacklists parameters:param method:@"POST" callBack:^(id responseObject) {
                    self.blacklist = @"1";
                    [self presentViewController:[LZCTools alertMessage:@"拉入黑名单成功"] animated:YES completion:nil];
                }];
                
            }]];
            
            [self presentViewController:alert2 animated:YES completion:nil];

        }
        
        else {
            
            NSString *url = [NSString stringWithFormat:@"%@/%@", APIUserBlacklists, self.to_user_id];
            
            [[NetworkTool sharedTool] requestWithName:@"解除黑名单" URLString:url parameters:nil method:@"DELETE" callBack:^(id responseObject) {
                self.blacklist = @"0";
                [self presentViewController:[LZCTools alertMessage:@"解除黑名单成功"] animated:YES completion:nil];
            }];
            
            
            
        }
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    
    [self presentViewController:alert animated:YES completion:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
